home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-13 | 21.2 KB | 787 lines | [TEXT/MPS ] |
- /*------------------------------------------------------------------------------
-
- File: TextEditorActivation.cpp
-
- Description: TextEditor's activation protocol methods.
-
- Written by: Steve Smith
-
- Copyright: © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
-
- ------------------------------------------------------------------------------*/
-
- // Notification that this is a SOM source file
- #define SampleCode_TextEditor_Class_Prototypes
- // define underscore (_) field names
- #define VARIABLE_MACROS
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (e.g. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- TextEditor Includes
-
- #ifndef SOM_SampleCode_TextEditor_xih
- #include "TextEditor.xih"
- #endif
-
- #ifndef _TEXTEDITORDEF_
- #include "TextEditorDef.h"
- #endif
-
- #ifndef _TEXTEDITORUTILS_
- #include "TextEditorUtils.h"
- #endif
-
- #ifndef _TEXTEDITORGLOBALS_
- #include "TextEditorGlobals.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- // -- Textension Includes --
-
- #ifndef _Textension_
- #include "Textension.h"
- #endif
-
- #ifndef _TSMTextension_
- #include "TSMTextension.h"
- #endif
-
- // -- ScriptRunner Includes --
-
- #ifndef SOM_PaletteExt_xh
- #include "PaletteExt.xh"
- #endif
-
-
- //------------------------------------------------------------------------------
- // Method: BeginRelinquishFocus
- // Origin: ODPart
- //
- // Description: This method is called when another part (or possibly
- // ourself) is requesting a focus for one of its display
- // frames. Returning true means we are willing to give
- // up the requested focus.
- //
- // The part willingly gives up any focus unless it is the
- // modal focus which we don't want to give up until we
- // are completely done displaying a modal dialog.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope ODBoolean
- SOMLINK TextEditor__BeginRelinquishFocus
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODTypeToken focus,
- ODFrame* ownerFrame,
- ODFrame* proposedFrame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","BeginRelinquishFocus");
-
- ODBoolean willRelinquish = kODTrue;
-
- SOM_TRY
-
- // Another part is trying to put up a Modal dialog while we
- // are currently displaying ours. Deny the request.
- if ( focus == gGlobals->fModalFocus )
- {
- TempODPart proposedPart = proposedFrame->AcquirePart(ev);
- if ( !ODObjectsAreEqual(ev, proposedPart, _fSelf) )
- willRelinquish = kODFalse;
- }
- else if (focus == gGlobals->fClipboardFocus)
- {
- // If the part has the clipboard focus, then a transaction is in
- // progress and we don't want to be interrupted.
- willRelinquish = kODFalse;
- }
-
- SOM_CATCH_ALL
- willRelinquish = kODTrue;
- SOM_ENDTRY
-
- return willRelinquish;
- }
-
- //------------------------------------------------------------------------------
- // Method: CommitRelinquishFocus
- // Origin: ODPart
- //
- // Description: This method is called when it is actually time to give
- // up a focus that had been requested by another part (or
- // possibly ourself).
- //
- // The part calls its FocusLost method to handle the
- // "reliquishing" of the particular focus.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope void
- SOMLINK TextEditor__CommitRelinquishFocus
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODTypeToken focus,
- ODFrame* ownerFrame,
- ODFrame* proposedFrame
- )
- {
- // SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","CommitRelinquishFocus");
-
- SOM_TRY
-
- // We agreed to give up the requested focus, so now we must do so.
- somSelf->FocusLost(ev, focus, ownerFrame);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: AbortRelinquishFocus
- // Origin: ODPart
- //
- // Description: This method is called when another part (or possibly
- // ourself) requested a focus for one of its display
- // frames, but we returned kODFalse from
- // BeginRelinqishFocus for one, or all, of the requested
- // focus. At this point, we are being told to resume
- // ownership of the focus.
- //
- // The part calls its FocusAcquired method to handle the
- // re-"acquisition" of the particular focus.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope void
- SOMLINK TextEditor__AbortRelinquishFocus
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODTypeToken focus,
- ODFrame* ownerFrame,
- ODFrame* proposedFrame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","AbortRelinquishFocus");
-
- // Some parts may have suspended some events in the BeginRelinquishFocus
- // method. If so, they would resume those events here.
- }
-
- //------------------------------------------------------------------------------
- // Method: RelinquishAllFoci
- // Origin: TextEditor
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope void
- SOMLINK TextEditor__RelinquishAllFoci
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","RelinquishAllFoci");
-
- SOM_TRY
-
- ODArbitrator* arbitrator = ODGetSession(ev, somSelf)->GetArbitrator(ev);
-
- TRY
-
- TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fSelectionFocus);
- if ( ODObjectsAreEqual(ev, focusFrame, frame) )
- {
- arbitrator->RelinquishFocus(ev, gGlobals->fSelectionFocus, frame);
- somSelf->FocusLost(ev, gGlobals->fSelectionFocus, frame);
- }
-
- CATCH_ALL
- ENDTRY
-
- TRY
-
- TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fMenuFocus);
- if ( ODObjectsAreEqual(ev, focusFrame, frame) )
- {
- arbitrator->RelinquishFocus(ev, gGlobals->fMenuFocus, frame);
- somSelf->FocusLost(ev, gGlobals->fMenuFocus, frame);
- }
-
- CATCH_ALL
- ENDTRY
-
- TRY
-
- TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fClipboardFocus);
- if ( ODObjectsAreEqual(ev, focusFrame, frame) )
- {
- arbitrator->RelinquishFocus(ev, gGlobals->fClipboardFocus, frame);
- somSelf->FocusLost(ev, gGlobals->fMenuFocus, frame);
- }
-
- CATCH_ALL
- ENDTRY
-
- TRY
-
- TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fKeyFocus);
- if ( ODObjectsAreEqual(ev, focusFrame, frame) )
- {
- arbitrator->RelinquishFocus(ev, gGlobals->fKeyFocus, frame);
- somSelf->FocusLost(ev, gGlobals->fKeyFocus, frame);
- }
-
- CATCH_ALL
- ENDTRY
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: PartActivated
- // Origin: TextEditor
- //
- // Description: This method is called when the part gets activated (by
- // asking for the contents of its focus set or having focus
- // transferred to it).
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope void
- SOMLINK TextEditor__PartActivated
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","PartActivated");
-
- SOM_TRY
-
- // We are required to re-validate the menubar before displaying it because
- // any part can/could swap the base menubar at any time.
- if ( !gGlobals->fMenuBar->IsValid(ev) )
- somSelf->LoadMenus(ev);
-
- // Display our menu bar.
- gGlobals->fMenuBar->Display(ev);
-
- // And set our "active" state.
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- frameInfo->SetFrameActive(kODTrue);
-
- // ScriptRunner support.
- if ( _fScriptPaletteExt && _fIsScriptRunnerOn )
- {
- _fScriptPaletteExt->Show(ev);
- _fScriptPaletteExt->SetClient(ev, _fSelf);
- _fIsScriptRunnerHidden = kODFalse;
- }
-
- // Set up Textension to get idle time.
- ODIdleFrequency ticks = _fTextension->GetIdleTime();
-
- ODGetSession(ev, somSelf)->GetDispatcher(ev)
- ->RegisterIdle(ev, _fSelf, frame, ++ticks);
-
- // While we are active, we don't need to use the bottom line input window.
- const TSMDocumentID kAnyDoc = kODNULL;
- UseInputWindow(kAnyDoc, kODFalse);
-
- // somSelf->ShowRulers()
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: FocusAcquired
- // Origin: ODPart
- //
- // Description: This method is called when the Arbitrator has
- // registered us as the "owner" of the particular focus.
- // This can occur if a focus is requested, or if a focus
- // is transfered to one of the part's display frames.
- //
- // The part will display the menu bar when the menu focus
- // is acquired, and mark a frame active if the selection
- // focus is acquired.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope void
- SOMLINK TextEditor__FocusAcquired
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODTypeToken focus,
- ODFrame* ownerFrame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","FocusAcquired");
-
- SOM_TRY
-
- if ( gGlobals->fUIFocusSet->Contains(ev, focus) )
- {
- if ( ODGetSession(ev, somSelf)->GetArbitrator(ev)
- ->RequestFocusSet(ev, gGlobals->fUIFocusSet, ownerFrame) )
- somSelf->PartActivated(ev, ownerFrame);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: FocusLost
- // Origin: ODPart
- //
- // Description: This method is called when the Arbitrator has
- // unregistered us as the "owner" of the particular
- // focus.
- //
- // The part unmarks the active frame if the selection
- // focus is lost.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope void
- SOMLINK TextEditor__FocusLost
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODTypeToken focus,
- ODFrame* ownerFrame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","FocusLost");
-
- SOM_TRY
-
- CFrameInfo* frameInfo = (CFrameInfo*) ownerFrame->GetPartInfo(ev);
-
- if ( focus == gGlobals->fSelectionFocus )
- {
- // Set our frame state flag.
- CFrameInfo* frameInfo = (CFrameInfo*) ownerFrame->GetPartInfo(ev);
- frameInfo->SetFrameActive(kODFalse);
-
- // Handle ScriptRunner.
- somSelf->UpdateScriptRunnerState(ev);
-
- if ( _fScriptPaletteExt && _fIsScriptRunnerOn )
- {
- // If script runner is "on", but has been hidden already for
- // some reason, we don't need to do anything.
- if ( !_fIsScriptRunnerHidden )
- {
- _fScriptPaletteExt->Hide(ev);
- _fIsScriptRunnerHidden = kODTrue;
- }
- }
-
- // Give up all foci.
- somSelf->RelinquishAllFoci(ev, ownerFrame);
- // •• Warning: this causes this section of code to be called once
- // recursively. This should be fixed in the future.
- }
- else if ( focus == gGlobals->fMenuFocus )
- {
- // Change the "Preferences" item back to the default.
- // NOTE: OpenDoc should do this for us, but there is a bug that
- // prevents it from doing so.
- SetMenuCommandIndString(ev, kODCommandPreferences, kRuntimeStringsID,
- kOriginalPreferencesStrIndex);
- }
- else if ( focus == gGlobals->fKeyFocus )
- {
- ODGetSession(ev, somSelf)->GetDispatcher(ev)
- ->UnregisterIdle(ev, _fSelf, ownerFrame);
-
- somSelf->ActivateTextension(ev, ownerFrame, kODFalse);
-
- // somSelf->HideRuler()
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
- //------------------------------------------------------------------------------
- // Method: FocusLost
- // Origin: ODPart
- //
- // Description: This method is called when we need to check to see if we have
- // the correct setting for our internal field tracking the visibility
- // of the ScriptRunner palette because the palette could have been
- // hidden by the user clicking in the close box, in which case we
- // don't get informed.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope void
- SOMLINK TextEditor__UpdateScriptRunnerState
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","FocusLost");
-
- SOM_TRY
-
- if ( _fScriptPaletteExt && _fIsScriptRunnerOn )
- {
- // If script runner is "on", but has been hidden already for
- // some reason, we don't need to do anything.
-
- if ( !_fIsScriptRunnerHidden )
- {
- // We need to check to see if we have the correct setting for
- // our internal field because the palette could have been hidden
- // by the user clicking in the close box, in which case we don't
- // get informed.
- if ( !_fScriptPaletteExt->IsPaletteVisible(ev) )
- {
- _fScriptPaletteExt->Hide(ev);
- ODReleaseObject(ev, _fScriptPaletteExt);
-
- _fIsScriptRunnerHidden = kODFalse;
- _fIsScriptRunnerOn = kODFalse;
-
- if ( !_fReadOnlyStorage )
- somSelf->SetDirty(ev);
- }
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: Activate
- // Origin: TextEditor
- //
- // Description: This method is called by the part when a kODEvtMouseUp
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope ODBoolean
- SOMLINK TextEditor__Activate
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","Activate");
-
- ODBoolean result = kODTrue;
-
- SOM_TRY
-
- ODWindow* window = facet->GetWindow(ev);
-
- // Activate inactive windows on the first mouse up event.
- if ( !window->IsActive(ev) )
- window->Select(ev);
- // Activate the frame (if needed) on all subsequent mouse up events.
- else
- {
- // Activate the frame (if needed).
-
- ODFrame* frame = facet->GetFrame(ev);
- CFrameInfo* frameInfo = (CFrameInfo*)frame->GetPartInfo(ev);
-
- ODBoolean active = kODTrue;
-
- // If this frame is not the active one, activate it by requesting
- // the appropriate foci.
-
- if ( frameInfo->IsFrameActive() == kODFalse )
- {
- if ( somSelf->ActivateFrame(ev, frame) )
- {
- // Keep track of which facet was the last active for
- // various maintenance/drawing reasons.
- frameInfo->SetActiveFacet(facet);
-
- // If the frame successfully becomes active, then
- // we activate Textension. Note that this call must
- // occur after the "active" facet has been set.
- somSelf->ActivateTextension(ev, frame, kODTrue);
- }
- else
- {
- // We were unsuccessful in activating our frame.
- result = kODFalse;
- }
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // Method: ActivateFrame
- // Origin: TextEditor
- //
- // Description: This method is called by the part when a kODEvtMouseUp
- // occurs in an inactive frame in an active window, and
- // when an OpenDoc document comes forward.
- //
- // The part activates the frame by requesting the
- // UIFocusSet (created in Initialize) and by calling
- // FocusAcquired if we were successful. The method
- // returns true if no problems were encountered as a
- // signal to the caller that the frame is now "active".
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope ODBoolean
- SOMLINK TextEditor__ActivateFrame
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","ActivateFrame");
-
- ODBoolean activated = kODFalse;
-
- SOM_TRY
-
- // Request the set of foci necessary to become active.
- if ( ODGetSession(ev, somSelf)->GetArbitrator(ev)
- ->RequestFocusSet(ev, gGlobals->fUIFocusSet, frame) )
- {
- // Activate the part.
- somSelf->PartActivated(ev, frame);
- // We were able to become active.
- activated = kODTrue;
- }
-
- SOM_CATCH_ALL
- activated = kODFalse;
- SOM_ENDTRY
-
- // We sucessfully acquired the foci we need to be active.
- return activated;
- }
-
- //------------------------------------------------------------------------------
- // Method: ActivateTextension
- // Origin: TextEditor
- //
- // Description: This method is called by the part when the text selection needs
- // to be activated or deactivated.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope void
- SOMLINK TextEditor__ActivateTextension
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame,
- ODBoolean activate
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","ActivateTextension");
-
- SOM_TRY
-
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- ODFacet* facet = frameInfo->GetActiveFacet();
-
- if ( facet )
- {
- CFocus initiateDrawing(ev, facet);
- _fTextension->Activate(activate);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: ActivateScrollbars
- // Origin: TextEditor
- //
- // Description: This method is called by the part when
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope void
- SOMLINK TextEditor__ActivateScrollbars
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODBoolean activate
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","ActivateScrollbars");
-
- SOM_TRY
-
- if ( _fVScrollbar )
- HiliteControl(_fVScrollbar, activate ? 0 : 255);
- if ( _fHScrollbar )
- HiliteControl(_fHScrollbar, activate ? 0 : 255);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: WindowActivating
- // Origin: TextEditor
- //
- // Description: This method is called by the part when a window activation
- // event (kODEvtActivate) occurs.
- //
- // The part remembers the frame's active state and restores it when
- // events come in. If the frame is active and the window is being
- // sent into the background, remember to reactivate the part when
- // the window is reactivated.
- //------------------------------------------------------------------------------
- #pragma segment TextEditorActivation
-
- SOM_Scope void
- SOMLINK TextEditor__WindowActivating
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame,
- ODBoolean activating
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","WindowActivating");
-
- // The ruler frame should never have an "active" facet, nor any foci, so
- // we don't want to set any "activation" flags.
- if ( frame->GetPresentation(ev) == gGlobals->fRulerPresentation )
- return;
-
- SOM_TRY
-
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- if ( activating && frameInfo->FrameNeedsReactivating() )
- {
- // The window is being activated, so acquire our foci.
- if ( somSelf->ActivateFrame(ev, frame) )
- {
- frameInfo->SetFrameReactivate(kODFalse);
-
- // If the frame successfully becomes active, then
- // we activate Textension. Note that this call must
- // occur after the "active" facet has been set.
- somSelf->ActivateTextension(ev, frame, kODTrue);
- }
- }
- else if ( !activating && frameInfo->IsFrameActive() )
- {
- // The window is being deactivated and we have the active part.
- // So give up our foci and remind ourselves that we need to request
- // the focus when the window is reactivated.
-
- frameInfo->SetFrameReactivate(kODTrue);
-
- // Give up all foci.
- somSelf->RelinquishAllFoci(ev, frame);
- }
-
- // De/activate the scrollbars.
- somSelf->ActivateScrollbars(ev, activating);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-